import request from '@/axios'
import { UserParams, UserResponse, UserSaveData } from '@/api/user/types'

export const getUserByIdApi = (params: UserParams): Promise<IResponse<UserResponse>> => {
  return request.get({ url: '/user/page', params })
}

export const saveUserApi = (data: UserSaveData) => {
  const url = data.id ? `/user/update/${data.id}` : '/user/create'
  const mapper = {
    update: request.put,
    create: request.post
  }
  return mapper[data.id ? 'update' : 'create']({ url, data })
}

export const resetDefaultPasswordApi = (id: number) => {
  return request.get({ url: `/user/reset-default-password/${id}` })
}
